Results 1 to 6 of 6

Thread: Drag 'n drop Tab inside and outside the Main Application

  1. #1
    Join Date
    Sep 2008
    Posts
    54
    Thanks
    3
    Thanked 10 Times in 5 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    2

    Default Drag 'n drop Tab inside and outside the Main Application

    With the help of QT Centre Movable Tabs Example I tried to create 'tear-off' tabs but it does not work. The functionality desired is the tabs drag 'n drop outside the application resulting in a new instance of that application. Examples are most Internet Browsers like Chrome/FireFox/IE etc.

    What should I do after creating a DragEvent in the QTabBar::moveMouseEvent?

    I guess while within the borders off the QMainWindow a DropEvent can be catched. But what if I drop outside the QMainWindow. How do I catch that event?

    Does anyone have an example of this functionality?

    Regards,

    Marcel

  2. #2
    Join Date
    Sep 2008
    Posts
    54
    Thanks
    3
    Thanked 10 Times in 5 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    2

    Default Re: Drag 'n drop Tab inside and outside the Main Application

    I created a solution that does work but also has some hick-ups. Maybe somebody has an idea what might be wrong:

    Requirements:

    1. Tabs are (animated) movable (QTabBar::setMovable)
    2. Tabs can be detached and attached by using the mouse and tear the tab off the tabbar.

    So I implemented it and you can see the code I attached DetachTabExample.zip.

    I have a few problems with this code:

    1. In the original application where I use the MHTabWidget and MHTabBar the tabbar does not seem to be updated after a detach.

    1. I tear the tab with the title 'Tab 3'. The dialog is created for 'Tab 4'.
    2. I am missing my widget but that will probably a simple mistake (removeTab and setParent might be a problem)
    3. But the tabbar shows the wrong tabs and wrong selections.
    See: AfterSelectTab3.png

    4. After clicking on a tab in the tabbar it gets updated
    5. And than I see both tab 3 and 4 are gone .
    See: DetachTab3.png

    2. When I detach the last tab of the bar ('Tab 6'). It looks like index 3 removes index 4.
    1. I get a QT error about a QList

    Regards,

    Marcel

  3. The following 2 users say thank you to mstegehu for this useful post:

    RazZziel (4th February 2014)

  4. #3
    Join Date
    Sep 2008
    Posts
    54
    Thanks
    3
    Thanked 10 Times in 5 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    2

    Default Re: Drag 'n drop Tab (Tear-off Detach TearOff Tabs)

    I solved the issues I had with the Detachable / Tear-Off Tabs and thought it might be nice to give you all the solution:

    Here the files are: DetachTabExample.pro

    Solved issues:

    1. TabBar update solved by turning off Moving while drag is initiated (Trick in TabBar::mouseMoveEvent)
    2. Widget not visible after reparent: call setVisible or show. The funny thing is that the Attach does work without setVisible.
    3. Wrong Tab: Called TabWidget for index / text after a reparent. Solved this. Also some interference due to movable tabs.
    4. 5. 6. 7. All solved by turning off movable tabs.

    Now I have two remaining features left:

    1. In the drag I show a screen shot off the widget. It would be nice if the Tab is shown also in that screen shot.
    2. It would be nice if a drag returns in the TabBar the Drag would stop and the move would continue.

    Hope somebody is helped with this solution.

    Regards,

    Marcel

  5. The following 2 users say thank you to mstegehu for this useful post:

    RazZziel (4th February 2014)

  6. #4
    Join Date
    Sep 2008
    Posts
    54
    Thanks
    3
    Thanked 10 Times in 5 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    2

    Default Re: Drag 'n drop Tab (Tear-off Detach TearOff Tabs)

    Hereby the example code.

    DetachTabExample.zip

  7. The following 3 users say thank you to mstegehu for this useful post:

    f.jacomme (23rd October 2013), RazZziel (4th February 2014)

  8. #5
    Join Date
    Sep 2008
    Posts
    54
    Thanks
    3
    Thanked 10 Times in 5 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    2

    Default Re: Drag 'n drop Tab (Tear-off Detach TearOff Tabs)

    With a minor change in QDrag::setDargCursor it is possible to set the drag cursor for the ignore action.

    QDrag setDragCursor allow change cursor for Qt::IgnoreAction

    Has someone an idea how to add a Tab to the pixmap of the drag?

  9. The following 2 users say thank you to mstegehu for this useful post:

    mitch (4th February 2013)

  10. #6
    Join Date
    May 2010
    Posts
    1
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Windows Symbian S60

    Smile Re: Drag 'n drop Tab inside and outside the Main Application

    from TabBar we can call

    QRect rect = tabRect( currentIndex() );

    QPixmap pixmap = grab(rect);

    It will be tab's screenshot.

    Your posted example is really nice. Thanks.

Similar Threads

  1. Drag and drop inside and outside a Widget
    By utopia500 in forum Qt Programming
    Replies: 1
    Last Post: 4th May 2010, 17:20
  2. Drag and drop inside and outside a Widget
    By utopia500 in forum Qt Programming
    Replies: 0
    Last Post: 3rd May 2010, 14:42
  3. Drag and Drop item inside QTreeWidget
    By nina1983 in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2008, 12:43
  4. Preventing drop/drag outside the main window
    By ucomesdag in forum Qt Programming
    Replies: 5
    Last Post: 26th February 2007, 11:42
  5. Drag and drop outside the application
    By jpn in forum Newbie
    Replies: 7
    Last Post: 27th August 2006, 16:37

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.